package org.atlantis.grosbeak.castor.defaults;

import java.lang.reflect.Type;

import org.atlantis.grosbeak.castor.Castor;
import org.atlantis.grosbeak.castor.FailToCastException;
import org.atlantis.grosbeak.lang.Strings;

public class StringToBoolean implements Castor<String, Boolean> {

	public Type getFrom() {
		return String.class;
	}

	public Type getTo() {
		return Boolean.class;
	}

	public Boolean obverseCast(String src, Class<?> toType)
			throws FailToCastException {
		if (Strings.isBlank(src))
			return false;
		return Boolean.valueOf(src);
	}

	public String reverseCast(Boolean src, Class<?> toType)
			throws FailToCastException {
		return String.valueOf(src);
	}
}
